home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / video / vesabios.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.9 KB  |  188 lines

  1. /*
  2.  * Copyright (C) 1990-1992 Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. /*
  15.  * vesabios.c    - interface to VESA video bios functions
  16.  */
  17. #include    <unistd.h>
  18.  
  19. #include    "v86mode.h"
  20. #include    "vbios.h"
  21. #include    "vesabios.h"
  22.  
  23. int
  24. VESAVersion()
  25. {
  26.     register struct tss386    *t = v86tss;
  27.     VESAInfo            *p;
  28.  
  29.     AX(t)    = VESA_INFO;
  30.     ES(t)    = VBIOS_SEG;
  31.     DI(t)    = 0x1000;
  32.  
  33.     VBiosINT10();
  34.  
  35.     if (AX(t) != VESA_RETURN_OK)
  36.     return -1;
  37.  
  38.     p        = (VESAInfo *)( (VBIOS_SEG << 4) + 0x1000 );
  39.  
  40.     return p->version;
  41. }
  42.  
  43. char *
  44. VESAVendorData()
  45. {
  46.     register struct tss386    *t = v86tss;
  47.     VESAInfo            *p;
  48.  
  49.     AX(t)    = VESA_INFO;
  50.     ES(t)    = VBIOS_SEG;
  51.     DI(t)    = 0x1000;
  52.  
  53.     VBiosINT10();
  54.  
  55.     if (AX(t) != VESA_RETURN_OK)
  56.     return NULL;
  57.  
  58.     p        = (VESAInfo *)( (VBIOS_SEG << 4) + 0x1000 );
  59.  
  60.     return (char *) ((SEGMENT(p->vendor_data) << 4) + OFFSET(p->vendor_data));
  61. }
  62.  
  63. unsigned short *
  64. VESAModeTable()
  65. {
  66.     register struct tss386    *t = v86tss;
  67.     VESAInfo            *p;
  68.  
  69.     AX(t)    = VESA_INFO;
  70.     ES(t)    = VBIOS_SEG;
  71.     DI(t)    = 0x1000;
  72.  
  73.     VBiosINT10();
  74.  
  75.     if (AX(t) != VESA_RETURN_OK)
  76.     return NULL;
  77.  
  78.     p        = (VESAInfo *)( (VBIOS_SEG << 4) + 0x1000 );
  79.  
  80.     return (unsigned short *) ((SEGMENT(p->mode_table) << 4) + OFFSET(p->mode_table));
  81. }
  82.  
  83. #if 0
  84. int
  85. VESAMemorySize()
  86. {
  87.     return 0;
  88. }
  89. #endif
  90.  
  91. VESAModeInfo *
  92. VESABiosGetModeInfo(
  93.     unsigned short    mode
  94.     )
  95. {
  96.     register struct tss386    *t = v86tss;
  97.  
  98.     AX(t)    = VESA_MODE_INFO;
  99.     CX(t)    = mode;
  100.     ES(t)    = VBIOS_SEG;
  101.     DI(t)    = 0x2000;
  102.  
  103.     VBiosINT10();
  104.  
  105.     if (AX(t) != VESA_RETURN_OK)
  106.     return NULL;
  107.  
  108.     return (VESAModeInfo *) ((VBIOS_SEG << 4) + 0x2000);
  109. }
  110.  
  111. int
  112. VESABiosSetMode(
  113.     int        mode
  114.     )
  115. {
  116.     register struct tss386    *t = v86tss;
  117.     int                r;
  118.  
  119.     if (mode >= 0x100)
  120.     {
  121.     AX(t)    = VESA_SET_MODE;
  122.     BX(t)    = (word_t) mode;
  123.     VBiosINT10();
  124.     r = (AX(t) == VESA_RETURN_OK) ? 0 : -1;
  125.     }
  126.     else
  127.     {
  128.     AH(t)    = 0;
  129.     AL(t)    = (byte_t) mode;
  130.     VBiosINT10();
  131.     AH(t)    = 0x0f;
  132.     VBiosINT10();
  133.     r = ((AL(t) & 0x7f) == (mode & 0x7f)) ? 0 : -1;
  134.     }
  135.  
  136.     return r;
  137. }
  138.  
  139. int
  140. VESABiosGetMode()
  141. {
  142.     register struct tss386    *t = v86tss;
  143.  
  144.     AH(t)    = 0x0f;
  145.  
  146.     VBiosINT10();
  147.  
  148.     return AL(t);
  149. }
  150.  
  151. int
  152. VESABiosBankSwitch(
  153.     unsigned short    bank
  154.     )
  155. {
  156.     register struct tss386    *t = v86tss;
  157.  
  158.     AX(t)    = VESA_WINDOW_CONTROL;
  159.     BX(t)    = 0;
  160.     DX(t)    = bank;
  161.  
  162.     VBiosINT10();
  163.  
  164.     return 0;
  165. }
  166.  
  167. int
  168. VESABiosGetDisplayStart(
  169.     int        *x,
  170.     int        *y
  171.     )
  172. {
  173.     register struct tss386    *t = v86tss;
  174.  
  175.     AX(t)    = VESA_DISPLAY_START;
  176.     BX(t)    = 0x01;
  177.  
  178.     VBiosINT10();
  179.  
  180.     if (AX(t) == VESA_RETURN_OK)
  181.     {
  182.     *x = CX(t);
  183.     *y = DX(t);
  184.     return 0;
  185.     }
  186.     return -1;
  187. }
  188.